export default {
    state: {
        hideMenus: false,
        keepAliveList: [], // 当前缓存页面列表
        routesList: null, // 用户路由权限列表---默认为null，标记区分未初始化与初始化后长度为0的情况，实际要求初始化类型为：Array
        menusList: [], // 用户权限菜单列表
    },
    getters: {},
    mutations: {
        // 设置缓存列表
        setKeepAliveLists(state, arrListString) {
            state.keepAliveList = Array.from(new Set(arrListString))
        },
        // 删除缓存页面name
        deleteKeepAliveLists(state, name) {
            if (state.keepAliveList.includes(name)) {
                state.keepAliveList.splice(
                    state.keepAliveList.findIndex(item => item === name),
                    1
                )
            }
        },
        // 添加缓存页面name
        addKeepAliveLists(state, name) {
            if (!state.keepAliveList.includes(name)) {
                state.keepAliveList = [...state.keepAliveList, ...[name]]
            }
        },
        // 更新路由列表数据
        setRoutesList(state, arr = []) {
            state.routesList = arr.map(v => {
                return {
                    path: v.path,
                    name: v.name,
                    meta: v.meta,
                }
            })
        },
        // 更新路由列表数据
        setMenuList(state, arrListString) {
            state.menusList = Array.from(new Set(arrListString))
        },
        // 头部菜单显示隐藏
        setHideMenus(state, hideMenus) {
            // 更新数据
            state.hideMenus = hideMenus.toString() === 'true'
        },
    },
    actions: {},
}
